package com.terrorism.sdk;

import java.io.File;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.support.v4.app.ShareCompat;

import com.terrorism.sdk.utils.AppUtils;
import com.terrorism.sdk.utils.FileUtils;

/**
 * @since Friday, June 20, 2014
 * @author hoangcaomobile
 *
 */
public class Intents {

	public static void vRateApp(final Context mContext) {
		try {
			Intent market = new Intent(Intent.ACTION_VIEW,
					Uri.parse("market://details?id=" + AppUtils.getAppPackage(mContext)));
			mContext.startActivity(market);
		} catch (android.content.ActivityNotFoundException anfe) {
			mContext.startActivity(new Intent(Intent.ACTION_VIEW,
					Uri.parse("http://play.google.com/store/apps/details?id=" + AppUtils.getAppPackage(mContext))));
		}
	}

	public static void vFeedback(Activity mActivity) {
		ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder.from(mActivity);
		builder.setType("message/rfc822");
		builder.addEmailTo("mayemail@cutepeer.com");
		builder.setSubject(AppUtils.getAppName(mActivity));
		builder.startChooser();
	}

	public static void vFanpage(Context mContext) {
		mContext.startActivity(new Intent(Intent.ACTION_VIEW, 
				Uri.parse("http://facebook.com/myfanpage")));
	}

	public static void vFanpage(Context mContext, String mURL) {
		mContext.startActivity(new Intent(Intent.ACTION_VIEW, 
				Uri.parse(mURL)));
	}

	public static void vOpenAppOnGooglePlay(final Context mContext, String mAppPackage) {
		try {
			Intent market = new Intent(Intent.ACTION_VIEW,
					Uri.parse("market://details?id=" + mAppPackage));
			mContext.startActivity(market);
		} catch (android.content.ActivityNotFoundException anfe) {
			mContext.startActivity(new Intent(Intent.ACTION_VIEW,
					Uri.parse("http://play.google.com/store/apps/details?id=" + mAppPackage)));
		}
	}

	public static void vShareText(Context mContext, String subject, String url) {
		Intent share = new Intent(android.content.Intent.ACTION_SEND);
		share.setType("text/plain");
		share.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
		share.putExtra(android.content.Intent.EXTRA_TEXT, url);
		mContext.startActivity(share);
	}

	public static void vShareFile(Context mContext, String filePath) {
		Intent share = new Intent(Intent.ACTION_SEND);
		share.setType(FileUtils.getFileMimeType(new File(filePath)));
		share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath));
		mContext.startActivity(Intent.createChooser(share, mContext.getString(R.string.dialogTitleShareFile)));
	}

	public static void vSharePhoto(Context mContext, String photoPath) {
		Intent share = new Intent(Intent.ACTION_SEND);
		share.setType("image/jpeg");
		share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + photoPath));
		mContext.startActivity(Intent.createChooser(share, mContext.getString(R.string.dialogTitleSharePhoto)));
	}

	public static void vShareAudio(Context mContext, String audioPath) {
		Uri uri = Uri.parse(audioPath);
		Intent share = new Intent(Intent.ACTION_SEND);
		share.setType("audio/*");
		share.putExtra(Intent.EXTRA_STREAM, uri);
		mContext.startActivity(Intent.createChooser(share, mContext.getString(R.string.dialogTitleShareAudio)));
	}

	public static void vOpenUrl(Context mContext, String url) {
		mContext.startActivity(new Intent(Intent.ACTION_VIEW, 
				Uri.parse(url)));
	}

	public static void vLocationSettings(Context mContext) {
		mContext.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
	}

	public static void vInternetSettings(final Context mContext) {
		Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
		mContext.startActivity(intent);		
	}

}
